import Vue from 'vue';

import Vuex from 'vuex';
import actions from './actions.js';
import mutations from './mutations.js';
import cart from './modules/cart.js';
import shop from './modules/shop.js';

import axios from 'axios';
const request = axios.create({
  baseURL: 'http://127.0.0.1:3009'
})

Vue.use(Vuex);

const store = new Vuex.Store({
  strict: process.env.NODE_ENV === 'development', // 开启严格模式
  state: () => ({
    title: 'root moudle',
    num: 0,
    lists: [],
  }),
  getters: {
    g1(state, getters) {
      return 'root g1' + state.title;
    },
    g2(state, getters) {
      return 'root g2'
    }
  },
  mutations,
  actions: {
    async getLists(store) {
      const { data } = await request.get('/lists');
      store.commit('SET_LISTS', data);
    }
  },
  modules: {
    cart,
    shop,
  }
});

export default store;